package com.ruoyi.project.platform.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.platform.domain.PltUserPlatform;
import com.ruoyi.project.platform.service.IPltUserPlatformService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户和交易所关联Controller
 * 
 * @author ruoyi
 * @date 2020-07-27
 */
@RestController
@RequestMapping("/platform/platform")
public class PltUserPlatformController extends BaseController
{
    @Autowired
    private IPltUserPlatformService pltUserPlatformService;

    /**
     * 查询用户和交易所关联列表
     */
    @PreAuthorize("@ss.hasPermi('platform:platform:list')")
    @GetMapping("/list")
    public TableDataInfo list(PltUserPlatform pltUserPlatform)
    {
        startPage();
        List<PltUserPlatform> list = pltUserPlatformService.selectPltUserPlatformList(pltUserPlatform);
        return getDataTable(list);
    }

    /**
     * 导出用户和交易所关联列表
     */
    @PreAuthorize("@ss.hasPermi('platform:platform:export')")
    @Log(title = "用户和交易所关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PltUserPlatform pltUserPlatform)
    {
        List<PltUserPlatform> list = pltUserPlatformService.selectPltUserPlatformList(pltUserPlatform);
        ExcelUtil<PltUserPlatform> util = new ExcelUtil<PltUserPlatform>(PltUserPlatform.class);
        return util.exportExcel(list, "platform");
    }

    /**
     * 获取用户和交易所关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:platform:query')")
    @GetMapping(value = "/{platform}")
    public AjaxResult getInfo(@PathVariable("platform") String platform)
    {
        return AjaxResult.success(pltUserPlatformService.selectPltUserPlatformById(platform));
    }

    /**
     * 新增用户和交易所关联
     */
    @PreAuthorize("@ss.hasPermi('platform:platform:add')")
    @Log(title = "用户和交易所关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PltUserPlatform pltUserPlatform)
    {
        return toAjax(pltUserPlatformService.insertPltUserPlatform(pltUserPlatform));
    }

    /**
     * 修改用户和交易所关联
     */
    @PreAuthorize("@ss.hasPermi('platform:platform:edit')")
    @Log(title = "用户和交易所关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PltUserPlatform pltUserPlatform)
    {
        return toAjax(pltUserPlatformService.updatePltUserPlatform(pltUserPlatform));
    }

    /**
     * 删除用户和交易所关联
     */
    @PreAuthorize("@ss.hasPermi('platform:platform:remove')")
    @Log(title = "用户和交易所关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{platforms}")
    public AjaxResult remove(@PathVariable String[] platforms)
    {
        return toAjax(pltUserPlatformService.deletePltUserPlatformByIds(platforms));
    }
}
